//
//  LDStatus.swift
//  Weibo201655
//
//  Created by pro on 16/5/9.
//  Copyright © 2016年 LeeDan. All rights reserved.
//

import UIKit

class LDStatus: NSObject {

    // 微博创建时间
    var created_at: String?
    
    // 微博ID
    var id:	Int64 = 0
    
    // 微博信息内容
    var text: String?
    
    // 微博来源
    var source: String?
    
    // 微博配图: 数组里面放的是字典
    var pic_urls: [[String: AnyObject]]? {
        didSet {
            if let _ = pic_urls?.count {
                // 创建数组,来保存图片的地址
                pictureUrls = [NSURL]()
                for dict in pic_urls! {
                    pictureUrls?.append(NSURL(string: (dict["thumbnail_pic"] as? String)!)!)
                }
            }
        }
    }
    
    // 转发数
    var reposts_count: Int = 0
    
    // 评论数
    var comments_count: Int = 0
    
    // 表态数
    var attitudes_count: Int = 0
    
    // 用户
    var user: LDUser?
    
    // 转发微博
    var retweeted_status: LDStatus?
    
    //配图路径数组
    var pictureUrls: [NSURL]?
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            // value是一个字典,字典转模型
            if let dict = value as? [String: AnyObject] {
                user = LDUser(dict: dict)
            }
            return
        }
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = LDStatus(dict: dict)
            }
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}

    override var description: String {
        
        let keys = ["created_at", "id", "text", "source", "pic_urls", "reposts_count", "comments_count", "attitudes_count", "user", "retweeted_status"]
       
        return "\n\t微博模型：\(dictionaryWithValuesForKeys(keys).description)"
    }
}
